﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdvanceLib.ScriptCore;
using AdvanceLib.AddIn;
using AdvanceLib.ScriptCore.DebugCore;

namespace AdvanceLib.Extension.XseScript.DebugPasses
{
    public class CommandExistsPass : CommandPass
    {
        #region Constructors
        public CommandExistsPass(XseExtensionProvider provider)
        {
            this._provider = provider;
        }
        #endregion

        #region Fields
        private XseExtensionProvider _provider;
        #endregion

        #region IterativeCommandDebugger Members
        public override void Pass(DebugResult result, string linePart)
        {
            if (this.CurrentLinePartIndex == 0 &&
                this._provider.Database.GetCommandDataByName(linePart) == null &&
                !string.IsNullOrEmpty(this.CurrentLine))
            {
                result.Errors.Add(new DebugError()
                {
                    Line = this.CurrentLineIndex,
                    Message = "Command " + '"' + linePart + '"' + " does not exist."
                });
            }
        }
        #endregion
    }
}
